#!/usr/local/python36/bin/python3.6
#coding:utf-8
#脚本中*****需要修改的地方
import pymysql
import config
#定义通过actionid和subject获取数据库告警具体信息，并以字典形式返回
def alerts_eventid(actionid,subject):

                conn=pymysql.connect(host=config.mysql_ip,user=config.mysql_user,passwd=config.mysql_pwd,db=config.mysql_db,port=config.mysql_port)
                #host：zabbix数据库ip
                #user：zabbix数据库用户
                #passwd：zabbix数据库密码
                #db：zabbix数据库名称
                cursor = conn.cursor()
                cursor.execute("SET NAMES utf8");
                sql = "SELECT * FROM alerts where actionid='%s' and subject='%s';" % (actionid,subject)
                cursor.execute(sql)
                data = cursor.fetchall()
                cursor.close()
                conn.close()
                if len(data) != 0:
                    event=data[0]
                    messagelist=[]
                    message=event[8]
                    messageone=message.split('#')
                    for i in messageone:
                            messagelist.append(i.split('|'))
                    messagedict=dict(messagelist)

                    return messagedict
                else:
                    t = "x1"
                    return t